package templateInherit;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class ObjectManager {

	private Map<String, ObjectBase> objs = new HashMap<>();
	
	public ObjectManager() {
		objs.put(MonsterObject.class.getName(), new MonsterObject());
		//objs.put(UnitObject.class.getName(), new UnitObject());
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getObj(Class<T> c) {
		ObjectBase t = objs.get(c.getName());
		return (T)t;
	}
	
	@SuppressWarnings("unchecked")
	public <T extends ObjectBase> Map<String, T> getObjs(Class<T> t) {
		Map<String, T> objs = new HashMap<>();
		for (ObjectBase worldObj : this.objs.values()) {
			if (t.isInstance(worldObj)) {
				objs.put(worldObj.getClass().getName(), (T)worldObj);
			}
		}
		
		return objs;
	}
	
	public <T> Optional<T> getOptionalObj(Class<T> c) {
		return Optional.ofNullable(getObj(c));
	}
}
